<?php
class Releases{

	function ListIndex($mysql,$style){
			// Thanks to Whoo @ WJ for help with this. Couldn't get my head around it (TFD)
			ob_start();
			$get = $mysql->query("select * from category where parent = 0"); 
			while($parent = mysql_fetch_object($get)){ 
			$get2  = $mysql->query("select * from category where parent = $parent->id ORDER BY id"); 
			$imgoffset = $parent->imgoffset;
			if($imgoffset > 0){ $imgoffset = "-".$imgoffset; }
		?>
		
		<table width="100%" onclick="$('cat#<?php echo $parent->id; ?>').slideToggle()"><tr>
		<td><div style="background-image:url(<?php echo $style; ?>img/22x22icons.png);background-position:<?php echo $imgoffset; ?>px;width:22px;height:22px"></div></td>
		<td><?php echo $parent->title; ?></td>
		<td><?php echo $parent->description; ?></td>
		</tr></table>
		
		<?php
			while($child = mysql_fetch_object($get2)) { 
			$get3 = $mysql->query("select * from category where parent = $child->id"); 
			$imgoffset = $child->imgoffset;
			if($imgoffset > 0){ $imgoffset = "-".$imgoffset; }
		?>
		
		<table style="margin-left:10px" width="100%" id="cat<?php echo $child->parent; ?>" onclick="$('#cat<?php echo $parent->id; ?>').slideToggle()"><tr>
		<td><div style="background-image:url(<?php echo $style; ?>img/22x22icons.png);background-position:<?php echo $imgoffset; ?>px;width:22px;height:22px"></div></td>
		<td><?php echo $child->title; ?></td>
		<td><?php echo $child->description; ?></td>
		</tr></table>
		
		<?php 
			while($grandchild = mysql_fetch_object($get3)){ 
			$imgoffset = $grandchild->imgoffset;
			if($imgoffset > 0){ $imgoffset = "-".$imgoffset; }
		?> 
		
		<table style="margin-left:10px" width="100%" id="cat<?php echo $child->parent; ?>"><tr>
		<td><div style="background-image:url(<?php echo $style; ?>img/22x22icons.png);background-position:<?php echo $imgoffset; ?>px;width:22px;height:22px"></div></td>
		<td><?php echo $grandchild->title; ?></td>
		<td><?php echo $grandchild->description; ?></td>
		</tr></table>
		
		<?php
				}
			}
		}
		
		$content = ob_get_flush();
		ob_clean();
		return $content;
	}
}
?>